// 用户相关的接口请求函数
import type { CodeType, PatientItem, User, UserInfo } from '@/types/user'
import { request } from '@/utils/request'

/**
 * @description: 密码登录
 * @param {string} mobile：手机号
 * @param {string} password：密码
 */
export const loginByPassword = (mobile: string, password: string) => {
  return request<User>('login/password', 'post', { mobile, password })
}

/**
 * @description: 发送验证码
 * @param {string} mobile
 * @param {CodeType} type：验证码类型
 */
export const sendMobileCode = (mobile: string, type: CodeType) => {
  return request<{ code: string }>('code', 'get', { mobile, type })
}

/**
 * @description: 发送验证码登录
 * @param {string} mobile
 * @param {string} code
 */
export const loginByCode = (mobile: string, code: string) => {
  return request<User>('login', 'post', { mobile, code })
}

/**
 * @description: 获取用户个人信息
 */
export const getUserInfo = () => {
  return request<UserInfo>('patient/myUser', 'get')
}

/**
 * @description: 获取患者列表 ==>  家庭档案
 */
export const getPatientList = () => request<PatientItem[]>('patient/mylist')

/**
 * @description: 添加患者
 * @param {patient}:就诊人信息
 */
export const addPatient = (patient: PatientItem) =>
  request('patient/add', 'post', patient)

/**
 * @description: 编辑患者信息
 * @param {PatientItem} patient：患者信息
 */
export const updatePatient = (patient: PatientItem) =>
  request('patient/update', 'put', patient)

/**
 * @description: 删除患者
 * @param {string} id：患者id
 */
export const deletePatient = (id: string) =>
  request(`patient/del/${id}`, 'delete')
